package cn.iocoder.yudao.module.train.service.payrefundorder;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.train.controller.admin.payrefundorder.vo.*;
import cn.iocoder.yudao.module.train.dal.dataobject.payrefundorder.PayRefundOrderDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.train.dal.mysql.payrefundorder.PayRefundOrderMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.train.enums.ErrorCodeConstants.*;

/**
 * 退款订单 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class PayRefundOrderServiceImpl implements PayRefundOrderService {

    @Resource
    private PayRefundOrderMapper payRefundOrderMapper;

    @Override
    public Long createPayRefundOrder(PayRefundOrderSaveReqVO createReqVO) {
        // 插入
        PayRefundOrderDO payRefundOrder = BeanUtils.toBean(createReqVO, PayRefundOrderDO.class);
        payRefundOrderMapper.insert(payRefundOrder);

        // 返回
        return payRefundOrder.getId();
    }

    @Override
    public Long createPayRefundOrder(PayRefundOrderDO createReqVO) {
        // 插入
        payRefundOrderMapper.insert(createReqVO);

        // 返回
        return createReqVO.getId();
    }

    @Override
    public void updatePayRefundOrder(PayRefundOrderSaveReqVO updateReqVO) {
        // 校验存在
        validatePayRefundOrderExists(updateReqVO.getId());
        // 更新
        PayRefundOrderDO updateObj = BeanUtils.toBean(updateReqVO, PayRefundOrderDO.class);
        payRefundOrderMapper.updateById(updateObj);
    }

    @Override
    public void deletePayRefundOrder(Long id) {
        // 校验存在
        validatePayRefundOrderExists(id);
        // 删除
        payRefundOrderMapper.deleteById(id);
    }

    @Override
        public void deletePayRefundOrderListByIds(List<Long> ids) {
        // 删除
        payRefundOrderMapper.deleteByIds(ids);
        }


    private void validatePayRefundOrderExists(Long id) {
        if (payRefundOrderMapper.selectById(id) == null) {
            throw exception(PAY_REFUND_ORDER_NOT_EXISTS);
        }
    }

    @Override
    public PayRefundOrderDO getPayRefundOrder(Long id) {
        return payRefundOrderMapper.selectById(id);
    }

    @Override
    public PageResult<PayRefundOrderDO> getPayRefundOrderPage(PayRefundOrderPageReqVO pageReqVO) {
        return payRefundOrderMapper.selectPage(pageReqVO);
    }

}
